<template>
  <div class="list-content">
    <div v-show="!dialogFalg">
      <el-form :inline="true" :model="formInline" class="demo-form-inline" @submit.native.prevent>
        <el-form-item>
          <el-input 
          v-model.trim="formInline.orgName" 
          placeholder="请输入单位名称"
          @keyup.enter.native="getData(1)"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button class="form-search-btn" type="primary" @click="getData(1)">查询</el-button>
        </el-form-item>
      </el-form>
      <el-row class="overview-wrap" :gutter="40">
        <el-col :span="12">
          <div class="item-wrap">
              <p class="item-value color-5">{{ staticObj.safeNum || 0 }}</p>
              <p class="item-title">具有安全管理制度的单位总数</p>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="item-wrap">
              <p class="item-value color-6">{{ staticObj.unSafeNum || 0}}</p>
              <p class="item-title">不具有安全管理制度的单位总数</p>
          </div>
        </el-col>
      </el-row>
      <el-table
        v-loading="loading"
        :data="tableData"
        ref="mainTable"
        style="width: 100%">
        <el-table-column
        label="序号"
        type="index"
        width="50">
        </el-table-column>
        <el-table-column
        prop="orgName"
        label="业主单位">
        </el-table-column>
        <el-table-column
        prop="count"
        label="安全管理制度数量">
        </el-table-column>
        <el-table-column 
        label="操作"
        width="140">
          <template slot-scope="scope">
            <el-button  @click="showDetail(scope.$index, scope.row)" type="text" size="small">清单</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        @size-change="sizeChange"
        @current-change="pageChange"
        :current-page="formInline.currentPageIndex"
        :page-sizes="[10, 50, 100]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="formInline.currentPageTotal">
      </el-pagination>
    </div>
    <transition name="el-zoom-in-top">
        <!-- 单个单位预案列表 -->
        <safe-list v-if="dialogFalg" :organizationId="transPageOrgId" :organizationName="transPageOrgName" :hasFather="hasFather" :returnFun="returnFather"></safe-list>
    </transition>
  </div>
</template>

<script>
import {getOrgSafeStatistics,getOrgSafeList } from '@/api/safeRule'
import util from '@/utils/util'
import safeList from './SafeRuleList'

export default {
  name: 'SafeRuleUnitList',
  props:['param'],
  components: { 
    safeList
  },
  data () {
    return {
      formInline: {
        orgName:'',
        currentPageSize: 10,
        currentPageIndex: 1,
        currentPageTotal: 0,
      },
      util:util,
      isMuilUnitUser:this.$store.state.userinfo.isMuilUnitUser,
      accountName:this.$store.state.userinfo.accountName,
      defaultImg: this.GLOBAL.defaultImg,
      tableData: [],//表格数据
      staticObj:{
        safeNum: '',
        unSafeNum: ''
      },//头部各状态个数统计
      loading: false,
      dialogFalg: false,
      hasFather: true,
      transPageOrgId: '',
      transPageOrgName: ''
    }
  },
  created:function() {
    this.getData()
  },
  methods: {
    getData(_pageIndex){
      this.getList(_pageIndex) 
      this.getStatis()    
    },
    sizeChange(_pageSize) {//页码切换
      this.getList(1,_pageSize) 
    },
    pageChange(_pageIndex) {//翻页
      this.getList(_pageIndex) 
    },
    getList(_pageIndex, _pageSize) {//获取列表
      if(_pageIndex){
        this.formInline.currentPageIndex = _pageIndex
      }
      if(_pageSize){
          this.formInline.currentPageSize = _pageSize
      }
      this.loading =true;
      getOrgSafeList({
        orgName: this.formInline.orgName.trim(),
        numberStart : 0,
        numberEnd : 1000,
        pageIndex: this.formInline.currentPageIndex -1,
        pageSize: this.formInline.currentPageSize,
      }).then((result) => {
        this.formInline.currentPageTotal = result.total;
        this.tableData = result.data;
        this.loading =false;
      }) 
    },
    getStatis() {//头部统计
      getOrgSafeStatistics({
        orgName:this.formInline.orgName.trim(),
        numberStart : 0,
        numberEnd : 1000
      }).then((result) => {
        this.staticObj.safeNum = result.data.safeNum
        this.staticObj.unSafeNum = result.data.unSafeNum
      })
    },
    showDetail(index, row) {//展开详情
      if(row) {
        this.transPageOrgId = row.orgId
        this.transPageOrgName = row.orgName
        this.dialogFalg = true
      }
    },
    // 返回父页面（供子组件调用）
    returnFather() {
        this.dialogFalg = false
        this.getData()
    }
  },
}
</script>